package com.hbl.xyl;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class AppCore {
    public static void main(String[] args) throws  Exception{
        /*Class<?> C = Class.forName("com.hbl.wm.CustomerService");
        Object c = C.newInstance();

        Field service = C.getDeclaredField("service");
        service.setAccessible(true);
        Class<?> U = Class.forName("com.hbl.wm.UserService");
        service.set(c,U.newInstance());

        Method say = C.getDeclaredMethod("say");
        say.invoke(c);*/

        Class<?> C = Class.forName("com.hbl.xyl.CoreService");
        Object c = C.newInstance();
        Field[] fileds = C.getDeclaredFields();
        for(int i = 0; i<fileds.length; i++){
            Field field=fileds[i];
            field.setAccessible(true);
            Class<?> type = field.getType();
            if(type.toString().endsWith("CustomerService")){
                Field customerService = C.getDeclaredField("customerService");
                customerService.setAccessible(true);
                Class<?> U = Class.forName("com.hbl.xyl.CustomerService");
                customerService.set(c,U.newInstance());
            }else if(type.toString().endsWith("OrderService")){
                Field orderService = C.getDeclaredField("orderService");
                orderService.setAccessible(true);
                Class<?> U1 = Class.forName("com.hbl.xyl.OrderService");
                orderService.set(c,U1.newInstance());
            }else if(type.toString().endsWith("UserService")){
                Field userService = C.getDeclaredField("userService");
                userService.setAccessible(true);
                Class<?> U2 = Class.forName("com.hbl.xyl.UserService");
                userService.set(c,U2.newInstance());
            }
        }



        Method say = C.getDeclaredMethod("say");
        say.invoke(c);

    }
}
